import java.util.Arrays;
import java.util.Random;

public class Test {
    public static void initOrder(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = array.length-i;
        }
    }

    public static void notOrder(int[] array) {
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(10000);
        }
    }

    public static void testInsert(int[] array) {
        int[] tempArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.insertSort(tempArray);
        long endTime = System.currentTimeMillis();
        System.out.println("直接插入排序耗时：" + (endTime-startTime));
    }

    public static void testShellSort(int[] array) {
        int[] tempArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.shellSort(tempArray);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔排序耗时：" + (endTime-startTime));
    }

    public static void testSelectSort(int[] array) {
        int[] tempArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.selectSort(tempArray);
        long endTime = System.currentTimeMillis();
        System.out.println("选择排序耗时：" + (endTime-startTime));
    }

    public static void testQuickSort(int[] array) {
        int[] tempArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.quickSort(tempArray);
        long endTime = System.currentTimeMillis();
        System.out.println("快速排序耗时：" + (endTime-startTime));
    }

    public static void testMergeSort(int[] array) {
        int[] tempArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.quickSort(tempArray);
        long endTime = System.currentTimeMillis();
        System.out.println("归并排序耗时：" + (endTime-startTime));
    }

    public static void main1(String[] args) {
        int[] array = new int[10_0000];
        notOrder(array);
        //testInsert(array);
        testShellSort(array);
        //testSelectSort(array);
        testQuickSort(array);
        testMergeSort(array);
    }

    public static void main(String[] args) {
        int[] array = {27,10,43,35,352,788,2,0,87};
        Sort.mergeSortNor(array);
        System.out.println(Arrays.toString(array));
    }
}
